﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Cloak.Mvvm.Navigation
{
	/// <summary>
	/// A reference to a type of view model associated with a page
	/// </summary>
	public class PageModelReference
	{
		/// <summary>
		/// Initializes an instace of <see cref="PageModelReference"/>
		/// </summary>
		/// <param name="viewModelType">The type of view model referenced by the page</param>
		/// <param name="parameters">The parameters available when resolving the view model</param>
		public PageModelReference(Type viewModelType, IEnumerable<PageModelParameter> parameters)
		{
			Contract.Requires(viewModelType != null);
			Contract.Requires(typeof(ViewModel).IsAssignableFrom(viewModelType));
			Contract.Requires(parameters != null);

			ViewModelType = viewModelType;
			Parameters = parameters.ToList().AsReadOnly();
		}

		/// <summary>
		/// Initializes an instace of <see cref="PageModelReference"/>
		/// </summary>
		/// <param name="viewModelType">The type of view model referenced by the page</param>
		/// <param name="parameters">The parameters available when resolving the view model</param>
		public PageModelReference(Type viewModelType, params PageModelParameter[] parameters)
			: this(viewModelType, parameters as IEnumerable<PageModelParameter>)
		{}

		/// <summary>
		/// Gets the type of view model referenced by the page
		/// </summary>
		public Type ViewModelType { get; private set; }

		/// <summary>
		/// Gets a collection of parameters available when resolving the view model
		/// </summary>
		public ReadOnlyCollection<PageModelParameter> Parameters { get; private set; }
	}
}